create 
--alter 
proc usp_XemDSCTDH_KH
@makh varchar(6)
as
begin tran
	begin try
		Select * from CTDONHANG a, DONHANG b where a.MaDH = b.MaDH and MaKH = @makh
	end try
	begin catch 
		
		declare @ErrorMsg varchar(2000)
		select @ErrorMsg = N'Loi: ' + ERROR_MESSAGE()
		raiserror(@ErrorMsg, 16,1)
		rollback tran
		return	
	end catch
commit tran

exec usp_XemDSCTDH_KH 'KH001'


---------------------------------------------------------------
-------huy CTDH----------------
create 
--alter 
proc usp_HuyDSCTDH_KH
@madh varchar(6),  @res int output
as
begin tran
	begin try
		if(@madh in(select MaDH from DONHANG))
		begin
			Delete from CTDONHANG where MaDH = @madh
			set @res = 1;
		end
		else
		begin
			set @res = 0;
		end
	end try
	begin catch 
		
		declare @ErrorMsg varchar(2000)
		select @ErrorMsg = N'Loi: ' + ERROR_MESSAGE()
		raiserror(@ErrorMsg, 16,1)
		rollback tran
		return	
	end catch
commit tran

Delete from CTDONHANG where MaDH in (select MaDH from DONHANG where MaDH = 'DH002')

select * from DONHANG
select * from CTDONHANG